package com.kantboot.business.water.balance;

import com.kantboot.business.water.service.IBusWaterVipService;
import com.kantboot.system.user.service.ISysUserBalanceService;
import com.kantboot.system.user.service.IUserSelfService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class BusWaterBalanceService {


    @Resource
    private ISysUserBalanceService userBalanceService;

    @Resource
    private IUserSelfService userSelfService;

    @Resource
    private IBusWaterVipService vipService;

    /**
     * 根据用户id获取消费总额
     * @return 消费总额
     */
    public BigDecimal getTotalConsumptionByUserId(Long userId) {
        return userBalanceService.getBalanceByCodeAndUserId("totalConsumption", userId).getNumber();
    }

    /**
     * 根据用户id获取当月消费
     * @return 当月消费
     */
    public BigDecimal getMonthConsumptionByUserId(Long userId) {
        return userBalanceService.getBalanceByCodeAndUserId("monthConsumption", userId).getNumber();
    }

    /**
     * 根据用户id获取平台积分
     * @return 平台积分
     */
    public BigDecimal getIntegralByUserId(Long userId) {
        return userBalanceService.getBalanceByCodeAndUserId("integral", userId).getNumber();
    }

    /**
     * 根据用户id获取用户当月剩余额度
     */
    public BigDecimal getMonthQuotaByUserId(Long userId) {
        return vipService.getByUserId(userId).getMonthlyQuota().subtract(getMonthConsumptionByUserId(userId));
    }


}
